package com.books.service.book.impl;/*
 *@Auther Zhourui
 *@data 2021/9/29  21:09
 *@Email 1605576647@qq.com
 */

import com.books.mapper.book.BookMapper;
import com.books.model.entity.book.BookType;
import com.books.model.entity.book.Books;
import com.books.service.book.IBookService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BookServiceImpl implements IBookService {

    @Autowired(required = false)
     private BookMapper bookMapper;

    @Override
    public Books getById(Integer id) {
        return bookMapper.getById(id);
    }

    @Override
    public List<Books> loadAll() {
        return bookMapper.findAll();
    }

    @Override
    public PageInfo<Books> index(String title, Integer categoryId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<Books> bookList = bookMapper.getAll(title,categoryId);

        PageInfo<Books> pageInfo = new PageInfo<>(bookList);

        return pageInfo;
    }

    @Override
    public void updateBookStock(Integer bkId, Integer stock) {
        bookMapper.updateBookStock(bkId,stock);
    }
}
